package com.hyj.shop.project.index.controller;

import com.hyj.shop.project.index.domain.Article;
import com.hyj.shop.project.index.service.IndexService;
import com.hyj.shop.project.utils.controller.BaseController;
import com.hyj.shop.project.utils.domain.AjaxResult;
import com.hyj.shop.project.utils.page.TableDataInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/api")
public class IndexController extends BaseController {
        @Autowired
       private IndexService indexService;
        @RequestMapping(value = "/articleList")
        @ResponseBody
        public TableDataInfo queryArticleByPage(Article article) {
            System.out.println("文章列表查询");
            startPage();
            List<Article> list =  indexService.queryArticleByPage(article);
            return getDataTable(list);


    }
    @RequestMapping(value = "/article/detail")
    @ResponseBody
    public AjaxResult queryArticleByPage(@RequestParam Integer articleId) {
        return indexService.articleDetail(articleId);
    }
    @RequestMapping(value = "/articleList/comment")
    @ResponseBody
    public AjaxResult articleComment(@RequestBody Map map) {
        System.out.println(map);
            // 文章评论
        return indexService.submitComment(map);
    }
    @GetMapping(value = "/articleList/comment/{articleId}")
    @ResponseBody
    public AjaxResult queryArticleComment(@PathVariable Integer articleId){
        System.out.println("------------------------");
        System.out.println(articleId);
        // 文章评论
        return indexService.queryComment(articleId);
    }
    @PostMapping(value = "/article/publish")
    @ResponseBody
    public AjaxResult publishArticle(@RequestBody Article article){
        System.out.println("------------------------");
        System.out.println(article);
        // 文章增加
        return indexService.publishArticle(article);
    }
    @PutMapping(value = "/article/publish")
    @ResponseBody
    public AjaxResult updateArticle(@RequestBody Article article){
        System.out.println("------------------------");
        System.out.println(article);
        // 文章增加
        return indexService.updateArticle(article);
    }
    @GetMapping(value = "/home/background")
    @ResponseBody
    public AjaxResult getHomeBackground(){
        System.out.println("------------------------");

        // 文章评论
        return indexService.getHomeBackground();
    }
}
